#ifndef N1STATICVARIABLE_H_2006_11_09
#define N1STATICVARIABLE_H_2006_11_09


template <class T>
class NEXPORT N1StaticVariable {
protected:
    typedef T MemberClass;
    static MemberClass *m_ptr;
    bool m_deleteInDestructor;

    void free() {
        if(m_ptr) delete m_ptr;
        m_ptr = NULL;
    }
    void alloc() {
        m_ptr = new MemberClass();
    }
    MemberClass* get() {
        if(!m_ptr) alloc();
        return m_ptr;
     }

public:
    N1StaticVariable(bool b=true) { 
        m_deleteInDestructor = b;
    };

    virtual ~N1StaticVariable() {
        if(m_deleteInDestructor)
            free();
    };

    operator T*() {
        return get();
    }

    T* operator ->() {
        return get();
    }

    T* operator =(T* ptr) {
        free();
        m_ptr = ptr;
        return m_ptr;
    }
};

template <class T>
class NEXPORT N1Variable {
protected:
    typedef T MemberClass;
    MemberClass *m_ptr;
    bool m_deleteInDestructor;

    void free() {
        if(m_ptr) delete m_ptr;
        m_ptr = NULL;
    }
    void alloc() {
        m_ptr = new MemberClass();
    }
    MemberClass* get() {
        if(!m_ptr) alloc();
        return m_ptr;
     }

public:
    N1Variable(bool b=true) { 
        m_deleteInDestructor = b;
    };

    virtual ~N1Variable() {
        if(m_deleteInDestructor)
            free();
    };

    operator T*() {
        return get();
    }

    T* operator ->() {
        return get();
    }

    T* operator =(T* ptr) {
        free();
        m_ptr = ptr;
        return m_ptr;
    }
};

#endif //N1STATICVARIABLE_H_2006_11_09
